home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / samples / ComboBox.tcl.z / ComboBox.tcl
Encoding:
Text File  |  1999-01-26  |  3.3 KB  |  116 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # This file demonstrates the use of the tixComboBox widget, which is close
  10. # to the MS Window Combo Box control.
  11. #
  12. proc RunSample {w} {
  13.  
  14.     # Create the comboboxes on the top of the dialog box
  15.     #
  16.     frame $w.top -border 1 -relief raised
  17.  
  18.     # $w.top.a is a drop-down combo box. It is not editable -- who wants
  19.     # to invent new months?
  20.     #
  21.     # [Hint] The -options switch sets the options of the subwidgets.
  22.     # [Hint] We set the label.width subwidget option of both comboboxes to 
  23.     #        be 10 so that their labels appear to be aligned.
  24.     #
  25.     tixComboBox $w.top.a -label "Month: " -dropdown true \
  26.     -command cbx:select_month -editable false -variable demo_month \
  27.     -options {
  28.         listbox.height 6
  29.         label.width 10
  30.         label.anchor e
  31.     }
  32.  
  33.  
  34.     # $w.top.b is a non-drop-down combo box. It is not editable: we provide
  35.     # four choices for the user, but he can enter an alternative year if he
  36.     # wants to.
  37.     #
  38.     # [Hint] Use the padY and anchor options of the label subwidget to
  39.     #         aligh the label with the entry subwidget.
  40.     # [Hint] Notice that you should use padY (the NAME of the option) and not
  41.     #        pady (the SWITCH of the option).
  42.     #
  43.     tixComboBox $w.top.b -label "Year: " -dropdown false \
  44.     -command cbx:select_year -editable true -variable demo_year \
  45.     -options {
  46.         listbox.height 4
  47.         label.padY 5
  48.         label.width 10
  49.         label.anchor ne
  50.     }
  51.  
  52.     pack $w.top.a -side top -anchor w
  53.     pack $w.top.b -side top -anchor w
  54.  
  55.     # Insert the choices into the combo boxes
  56.     #
  57.     $w.top.a insert end January
  58.     $w.top.a insert end February
  59.     $w.top.a insert end March
  60.     $w.top.a insert end April
  61.     $w.top.a insert end May
  62.     $w.top.a insert end June
  63.     $w.top.a insert end July
  64.     $w.top.a insert end August
  65.     $w.top.a insert end September
  66.     $w.top.a insert end October
  67.     $w.top.a insert end November
  68.     $w.top.a insert end December
  69.  
  70.     $w.top.b insert end 1992
  71.     $w.top.b insert end 1993
  72.     $w.top.b insert end 1994
  73.     $w.top.b insert end 1995
  74.  
  75.     # Use "tixSetSilent" to set the values of the combo box if you
  76.     # don't want your -command procedures (cbx:select_month and 
  77.     # cbx:select_year) to be called.
  78.     #
  79.     tixSetSilent $w.top.a January
  80.     tixSetSilent $w.top.b 1995
  81.  
  82.     # Use a ButtonBox to hold the buttons.
  83.     #
  84.     tixButtonBox $w.box -orientation horizontal
  85.     $w.box add ok     -text Ok     -underline 0 -command "cbx:okcmd $w" \
  86.     -width 6
  87.     $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  88.     -width 6
  89.  
  90.     pack $w.box -side bottom -fill x
  91.     pack $w.top -side top -fill both -expand yes
  92. }
  93.  
  94. proc cbx:select_year {args} {
  95.     puts "you have selected \"$args\""
  96. }
  97.  
  98. proc cbx:select_month {s} {
  99.     puts "you have selected \"$s\""
  100. }
  101.  
  102. proc cbx:okcmd {w} {
  103.     global demo_month demo_year
  104.  
  105.     puts "The month selected is $demo_month of $demo_year"
  106.     destroy $w
  107. }
  108.  
  109. if {![info exists tix_demo_running]} {
  110.     wm withdraw .
  111.     set w .demo
  112.     toplevel $w
  113.     RunSample $w
  114.     bind $w <Destroy> exit
  115. }
  116.